<?php echo $header; ?>
<div class="box">
    <div class="content">
        <h2 class="h2title">Authorize Personal</h2>
        <div>
            <div class="warning" style="margin-top:10px;display:none;">
            </div>
            <table style="width:100%;padding:20px;">
                <tr>
                    <td align="right">
                    <span class="spanlablebold" style="margin-right:5px;">Department</span>
					</td>
                    <td>
                        <select id="seldept" class="sel" style="width: 205px;">
                            <option value="">--select--</option>
                            <?php foreach($department as $row){ ?>
                            <option value="<?php echo $row["department_id"]; ?>">
                                <?php echo $row["name"]; ?>
                            </option>
                            <?php } ?>
                        </select>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Personal Name</span>
                    </td>
                    <td>
                        <select id="seluser" class="sel" style="width: 205px;">
                            <option value="">--select--</option>
                            <?php foreach($user_list as $row){ ?>
                            <option value="<?php echo $row["user_id"]; ?>">
                                <?php echo $row["username"]; ?>
                            </option>
                            <?php } ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Personal Designation</span>
                    </td>
                    <td>
                        <input type="text" id="txtdesignation" name="txtdesignation" class="txt" maxlength="50"/>
                    </td>
                    <td align="right">
                        <span class="spanlablebold" style="margin-right:5px;">Priviledge Level</span>
                    </td>
                    <td>
                        <select id="selpriviledgelevel" class="sel" style="width: 205px;">
                            <option value="">--select--</option>
                            <option value="1">Level 1</option>
                            <option value="2">Level 2</option>
                            <option value="3">Level 3</option>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="buttonbar">
    <input type="button" value="Save" id="btnsave" name="btnsave" class="btnradius" style="margin-right:10px;"/><input type="button" value="Reset" id="btnreset" name="btnreset" class="btnradius"/>
</div>
<script type="text/javascript">
    
    $("#btnsave").click(function(){
        if (validate()) {
            loading("show");
            $.ajax({
                url: "<?php echo MAIN_PAGE.'authorization/authorizationpost';?>",
                type: 'POST',
                data: {
                 deptid:$("#seldept").val(),
				 userid:$("#seluser").val(),
				 designation:$("#txtdesignation").val(),
				 level:$("#selpriviledgelevel").val()
                },
                dataType: 'json',
                success: function(res){
                    loading('hide');
                    if (res.status) {
                        $("#btnreset").trigger("click");
                        alert(res.msg);
                    }
                    else {
                        alert(res.msg);
                    }
                }
            });
        }
    });
    
    function validate(){
        $(".warning").hide();
        if ($("#seldept").val() == "") {
            $("#seldept").focus();
            $(".warning").text("Please choose department").show();
            return false;
        }
        if ($("#seluser").val() == "") {
            $("#seluser").focus();
            $(".warning").text("Please choose personal name").show();
            return false;
        }
        if ($("#txtdesignation").val() == "") {
            $("#txtdesignation").focus();
            $(".warning").text("Please enter personal designation").show();
            return false;
        }
        if ($("#selpriviledgelevel").val() == "") {
            $("#selpriviledgelevel").focus();
            $(".warning").text("Please choose priviledge level").show();
            return false;
        }
        return true;
    }
    
    $("#btnreset").click(function(){
        $("#seldept option:first").attr('selected', 'selected');
        $("#seluser option:first").attr('selected', 'selected');
        $("#selpriviledgelevel option:first").attr('selected', 'selected');
        $("#txtdesignation").val("");
    });
</script>
<?php echo $footer;?>
